using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace sharpTV.Entities
{
	/// <summary>
	/// Strongly-typed collection for the Contact class.
	/// </summary>
    [Serializable]
	public partial class ContactCollection : ActiveList<Contact, ContactCollection>
	{	   
		public ContactCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>ContactCollection</returns>
		public ContactCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                Contact o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the sharpTV_Contacts table.
	/// </summary>
	[Serializable]
	public partial class Contact : ActiveRecord<Contact>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Contact()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Contact(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Contact(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Contact(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("sharpTV_Contacts", TableType.Table, DataService.GetInstance("sharpTVSubSonicProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarContactId = new TableSchema.TableColumn(schema);
				colvarContactId.ColumnName = "ContactId";
				colvarContactId.DataType = DbType.Int32;
				colvarContactId.MaxLength = 0;
				colvarContactId.AutoIncrement = true;
				colvarContactId.IsNullable = false;
				colvarContactId.IsPrimaryKey = true;
				colvarContactId.IsForeignKey = false;
				colvarContactId.IsReadOnly = false;
				colvarContactId.DefaultSetting = @"";
				colvarContactId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarContactId);
				
				TableSchema.TableColumn colvarContactUId = new TableSchema.TableColumn(schema);
				colvarContactUId.ColumnName = "ContactUId";
				colvarContactUId.DataType = DbType.Guid;
				colvarContactUId.MaxLength = 0;
				colvarContactUId.AutoIncrement = false;
				colvarContactUId.IsNullable = true;
				colvarContactUId.IsPrimaryKey = false;
				colvarContactUId.IsForeignKey = false;
				colvarContactUId.IsReadOnly = false;
				
						colvarContactUId.DefaultSetting = @"(newid())";
				colvarContactUId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarContactUId);
				
				TableSchema.TableColumn colvarTitle = new TableSchema.TableColumn(schema);
				colvarTitle.ColumnName = "Title";
				colvarTitle.DataType = DbType.String;
				colvarTitle.MaxLength = 16;
				colvarTitle.AutoIncrement = false;
				colvarTitle.IsNullable = true;
				colvarTitle.IsPrimaryKey = false;
				colvarTitle.IsForeignKey = false;
				colvarTitle.IsReadOnly = false;
				
						colvarTitle.DefaultSetting = @"(N'')";
				colvarTitle.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTitle);
				
				TableSchema.TableColumn colvarFirstName = new TableSchema.TableColumn(schema);
				colvarFirstName.ColumnName = "FirstName";
				colvarFirstName.DataType = DbType.String;
				colvarFirstName.MaxLength = 64;
				colvarFirstName.AutoIncrement = false;
				colvarFirstName.IsNullable = true;
				colvarFirstName.IsPrimaryKey = false;
				colvarFirstName.IsForeignKey = false;
				colvarFirstName.IsReadOnly = false;
				
						colvarFirstName.DefaultSetting = @"(N'')";
				colvarFirstName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFirstName);
				
				TableSchema.TableColumn colvarSecondName = new TableSchema.TableColumn(schema);
				colvarSecondName.ColumnName = "SecondName";
				colvarSecondName.DataType = DbType.String;
				colvarSecondName.MaxLength = 64;
				colvarSecondName.AutoIncrement = false;
				colvarSecondName.IsNullable = true;
				colvarSecondName.IsPrimaryKey = false;
				colvarSecondName.IsForeignKey = false;
				colvarSecondName.IsReadOnly = false;
				
						colvarSecondName.DefaultSetting = @"(N'')";
				colvarSecondName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSecondName);
				
				TableSchema.TableColumn colvarLastName = new TableSchema.TableColumn(schema);
				colvarLastName.ColumnName = "LastName";
				colvarLastName.DataType = DbType.String;
				colvarLastName.MaxLength = 64;
				colvarLastName.AutoIncrement = false;
				colvarLastName.IsNullable = true;
				colvarLastName.IsPrimaryKey = false;
				colvarLastName.IsForeignKey = false;
				colvarLastName.IsReadOnly = false;
				
						colvarLastName.DefaultSetting = @"(N'')";
				colvarLastName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLastName);
				
				TableSchema.TableColumn colvarEmail = new TableSchema.TableColumn(schema);
				colvarEmail.ColumnName = "Email";
				colvarEmail.DataType = DbType.String;
				colvarEmail.MaxLength = 256;
				colvarEmail.AutoIncrement = false;
				colvarEmail.IsNullable = true;
				colvarEmail.IsPrimaryKey = false;
				colvarEmail.IsForeignKey = false;
				colvarEmail.IsReadOnly = false;
				
						colvarEmail.DefaultSetting = @"(N'')";
				colvarEmail.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEmail);
				
				TableSchema.TableColumn colvarWebsite = new TableSchema.TableColumn(schema);
				colvarWebsite.ColumnName = "Website";
				colvarWebsite.DataType = DbType.String;
				colvarWebsite.MaxLength = 256;
				colvarWebsite.AutoIncrement = false;
				colvarWebsite.IsNullable = true;
				colvarWebsite.IsPrimaryKey = false;
				colvarWebsite.IsForeignKey = false;
				colvarWebsite.IsReadOnly = false;
				
						colvarWebsite.DefaultSetting = @"(N'')";
				colvarWebsite.ForeignKeyTableName = "";
				schema.Columns.Add(colvarWebsite);
				
				TableSchema.TableColumn colvarContactType = new TableSchema.TableColumn(schema);
				colvarContactType.ColumnName = "ContactType";
				colvarContactType.DataType = DbType.Int32;
				colvarContactType.MaxLength = 0;
				colvarContactType.AutoIncrement = false;
				colvarContactType.IsNullable = true;
				colvarContactType.IsPrimaryKey = false;
				colvarContactType.IsForeignKey = false;
				colvarContactType.IsReadOnly = false;
				colvarContactType.DefaultSetting = @"";
				colvarContactType.ForeignKeyTableName = "";
				schema.Columns.Add(colvarContactType);
				
				TableSchema.TableColumn colvarUserId = new TableSchema.TableColumn(schema);
				colvarUserId.ColumnName = "UserId";
				colvarUserId.DataType = DbType.Int32;
				colvarUserId.MaxLength = 0;
				colvarUserId.AutoIncrement = false;
				colvarUserId.IsNullable = true;
				colvarUserId.IsPrimaryKey = false;
				colvarUserId.IsForeignKey = false;
				colvarUserId.IsReadOnly = false;
				colvarUserId.DefaultSetting = @"";
				colvarUserId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserId);
				
				TableSchema.TableColumn colvarIsRegisteredUser = new TableSchema.TableColumn(schema);
				colvarIsRegisteredUser.ColumnName = "IsRegisteredUser";
				colvarIsRegisteredUser.DataType = DbType.Boolean;
				colvarIsRegisteredUser.MaxLength = 0;
				colvarIsRegisteredUser.AutoIncrement = false;
				colvarIsRegisteredUser.IsNullable = true;
				colvarIsRegisteredUser.IsPrimaryKey = false;
				colvarIsRegisteredUser.IsForeignKey = false;
				colvarIsRegisteredUser.IsReadOnly = false;
				
						colvarIsRegisteredUser.DefaultSetting = @"((0))";
				colvarIsRegisteredUser.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsRegisteredUser);
				
				TableSchema.TableColumn colvarCreationDate = new TableSchema.TableColumn(schema);
				colvarCreationDate.ColumnName = "CreationDate";
				colvarCreationDate.DataType = DbType.DateTime;
				colvarCreationDate.MaxLength = 0;
				colvarCreationDate.AutoIncrement = false;
				colvarCreationDate.IsNullable = true;
				colvarCreationDate.IsPrimaryKey = false;
				colvarCreationDate.IsForeignKey = false;
				colvarCreationDate.IsReadOnly = false;
				
						colvarCreationDate.DefaultSetting = @"(getdate())";
				colvarCreationDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreationDate);
				
				TableSchema.TableColumn colvarOwner = new TableSchema.TableColumn(schema);
				colvarOwner.ColumnName = "Owner";
				colvarOwner.DataType = DbType.Guid;
				colvarOwner.MaxLength = 0;
				colvarOwner.AutoIncrement = false;
				colvarOwner.IsNullable = true;
				colvarOwner.IsPrimaryKey = false;
				colvarOwner.IsForeignKey = false;
				colvarOwner.IsReadOnly = false;
				colvarOwner.DefaultSetting = @"";
				colvarOwner.ForeignKeyTableName = "";
				schema.Columns.Add(colvarOwner);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["sharpTVSubSonicProvider"].AddSchema("sharpTV_Contacts",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("ContactId")]
		[Bindable(true)]
		public int ContactId 
		{
			get { return GetColumnValue<int>(Columns.ContactId); }
			set { SetColumnValue(Columns.ContactId, value); }
		}
		  
		[XmlAttribute("ContactUId")]
		[Bindable(true)]
		public Guid? ContactUId 
		{
			get { return GetColumnValue<Guid?>(Columns.ContactUId); }
			set { SetColumnValue(Columns.ContactUId, value); }
		}
		  
		[XmlAttribute("Title")]
		[Bindable(true)]
		public string Title 
		{
			get { return GetColumnValue<string>(Columns.Title); }
			set { SetColumnValue(Columns.Title, value); }
		}
		  
		[XmlAttribute("FirstName")]
		[Bindable(true)]
		public string FirstName 
		{
			get { return GetColumnValue<string>(Columns.FirstName); }
			set { SetColumnValue(Columns.FirstName, value); }
		}
		  
		[XmlAttribute("SecondName")]
		[Bindable(true)]
		public string SecondName 
		{
			get { return GetColumnValue<string>(Columns.SecondName); }
			set { SetColumnValue(Columns.SecondName, value); }
		}
		  
		[XmlAttribute("LastName")]
		[Bindable(true)]
		public string LastName 
		{
			get { return GetColumnValue<string>(Columns.LastName); }
			set { SetColumnValue(Columns.LastName, value); }
		}
		  
		[XmlAttribute("Email")]
		[Bindable(true)]
		public string Email 
		{
			get { return GetColumnValue<string>(Columns.Email); }
			set { SetColumnValue(Columns.Email, value); }
		}
		  
		[XmlAttribute("Website")]
		[Bindable(true)]
		public string Website 
		{
			get { return GetColumnValue<string>(Columns.Website); }
			set { SetColumnValue(Columns.Website, value); }
		}
		  
		[XmlAttribute("ContactType")]
		[Bindable(true)]
		public int? ContactType 
		{
			get { return GetColumnValue<int?>(Columns.ContactType); }
			set { SetColumnValue(Columns.ContactType, value); }
		}
		  
		[XmlAttribute("UserId")]
		[Bindable(true)]
		public int? UserId 
		{
			get { return GetColumnValue<int?>(Columns.UserId); }
			set { SetColumnValue(Columns.UserId, value); }
		}
		  
		[XmlAttribute("IsRegisteredUser")]
		[Bindable(true)]
		public bool? IsRegisteredUser 
		{
			get { return GetColumnValue<bool?>(Columns.IsRegisteredUser); }
			set { SetColumnValue(Columns.IsRegisteredUser, value); }
		}
		  
		[XmlAttribute("CreationDate")]
		[Bindable(true)]
		public DateTime? CreationDate 
		{
			get { return GetColumnValue<DateTime?>(Columns.CreationDate); }
			set { SetColumnValue(Columns.CreationDate, value); }
		}
		  
		[XmlAttribute("Owner")]
		[Bindable(true)]
		public Guid? Owner 
		{
			get { return GetColumnValue<Guid?>(Columns.Owner); }
			set { SetColumnValue(Columns.Owner, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid? varContactUId,string varTitle,string varFirstName,string varSecondName,string varLastName,string varEmail,string varWebsite,int? varContactType,int? varUserId,bool? varIsRegisteredUser,DateTime? varCreationDate,Guid? varOwner)
		{
			Contact item = new Contact();
			
			item.ContactUId = varContactUId;
			
			item.Title = varTitle;
			
			item.FirstName = varFirstName;
			
			item.SecondName = varSecondName;
			
			item.LastName = varLastName;
			
			item.Email = varEmail;
			
			item.Website = varWebsite;
			
			item.ContactType = varContactType;
			
			item.UserId = varUserId;
			
			item.IsRegisteredUser = varIsRegisteredUser;
			
			item.CreationDate = varCreationDate;
			
			item.Owner = varOwner;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varContactId,Guid? varContactUId,string varTitle,string varFirstName,string varSecondName,string varLastName,string varEmail,string varWebsite,int? varContactType,int? varUserId,bool? varIsRegisteredUser,DateTime? varCreationDate,Guid? varOwner)
		{
			Contact item = new Contact();
			
				item.ContactId = varContactId;
			
				item.ContactUId = varContactUId;
			
				item.Title = varTitle;
			
				item.FirstName = varFirstName;
			
				item.SecondName = varSecondName;
			
				item.LastName = varLastName;
			
				item.Email = varEmail;
			
				item.Website = varWebsite;
			
				item.ContactType = varContactType;
			
				item.UserId = varUserId;
			
				item.IsRegisteredUser = varIsRegisteredUser;
			
				item.CreationDate = varCreationDate;
			
				item.Owner = varOwner;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn ContactIdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn ContactUIdColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn TitleColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn FirstNameColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn SecondNameColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn LastNameColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn EmailColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn WebsiteColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        public static TableSchema.TableColumn ContactTypeColumn
        {
            get { return Schema.Columns[8]; }
        }
        
        
        
        public static TableSchema.TableColumn UserIdColumn
        {
            get { return Schema.Columns[9]; }
        }
        
        
        
        public static TableSchema.TableColumn IsRegisteredUserColumn
        {
            get { return Schema.Columns[10]; }
        }
        
        
        
        public static TableSchema.TableColumn CreationDateColumn
        {
            get { return Schema.Columns[11]; }
        }
        
        
        
        public static TableSchema.TableColumn OwnerColumn
        {
            get { return Schema.Columns[12]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string ContactId = @"ContactId";
			 public static string ContactUId = @"ContactUId";
			 public static string Title = @"Title";
			 public static string FirstName = @"FirstName";
			 public static string SecondName = @"SecondName";
			 public static string LastName = @"LastName";
			 public static string Email = @"Email";
			 public static string Website = @"Website";
			 public static string ContactType = @"ContactType";
			 public static string UserId = @"UserId";
			 public static string IsRegisteredUser = @"IsRegisteredUser";
			 public static string CreationDate = @"CreationDate";
			 public static string Owner = @"Owner";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
